#!/usr/bin/env osascript

on move_to_next_space()
--move to next desktop
tell application "System Events"
	tell application "System Events" to key code 124 using control down
	activate
	delay 2
end tell
end move_to_next_space

on open_terminal(x, y, r, c)
	using terms from application "Terminal"
    	tell application "Terminal"
		activate
		tell application "System Events" to keystroke "n" using command down
		repeat while contents of selected tab of window 1 starts with linefeed
			delay 0.01
		end repeat

		tell application "System Events" to keystroke "t" using command down
		repeat while contents of selected tab of window 1 starts with linefeed
			delay 0.01
		end repeat

        delay 0.2
		set bounds of window 1 to {x,y,r,c}
		--do script "pwd" in window 1

		--set bounds of id_w of window to {x, y, r, c}

		--set position of front window  to {100, 10}
		--set size of front window  to {1400, 800}
		--set bounds of front window  to {0, 0,1400,825}

		--set nameofwind to first window
		--log nameofwind
		--set bounds of nameofwind  to {x, y,r,c}
		--delay 1
	end tell
			-- tell application "Terminal"
            --     --open ~/.vimrc
            --     --open /bin/bash
            --     do script "pwd"
            --     activate
            --       set id_w to  get id of  window
            --       log id_w
            --     tell application "System Events" to keystroke "t" using command down

            --     set bounds of id_w of window  to {x, y,r,c}

            --     --set position of front window  to {100, 10}
            --     --set size of front window  to {1400, 800}
            --     --set bounds of front window  to {0, 0,1400,825}

            --     --set nameofwind to first window
            --     --log nameofwind
            --     --set bounds of nameofwind  to {x, y,r,c}
            --     --delay 1
			-- end tell

            
	end using terms from
end open_terminal

(*
tell application "Google Chrome"
    activate 
    open location "https://www.google.com"
end tell

move_to_next_space()
*)

on get_screen_size()
    tell application "Finder" to get bounds of window of desktop
end get_screen_size 
---------------------------------------------------------
--open terminal
set xx to 870
set width to 1440
set yy to 456
set ww to 570
--set hh to 365
set hh to 390

set height_toolbar to 25
set dock_height to 55  --it is mutable, because user maybe change dock size
--set termainal_width to 585 
set termainal_width to 570
set termainal_height to 391 --default window height of termainl with at least two tabs, tabs title height is 20px

--set screen_size to osascript -e 'tell application "Finder" to get bounds of window of desktop'
--获取当前terminal窗口size
--osascript -e 'tell application "Terminal" to get bounds of window 1'
set screen_point to get_screen_size()
--log screen_point

set screen_p1x to 0
set screen_p1y to height_toolbar

set screen_p2x to item 3 of screen_point
set screen_p2y to item 4 of screen_point - dock_height

--log screen_p2x
--log screen_p2y 

--open_terminal(xx, 0, 24, 80)
--open_terminal(xx, yy, 24, 80)
--open_terminal(0, 0, 71, 198)
--open_terminal(xx, 0, ww, hh)

--log height_toolbar
open_terminal(screen_p2x-termainal_width, height_toolbar, screen_p2x, height_toolbar+termainal_height)
open_terminal(screen_p2x-termainal_width, screen_p2y-termainal_height, screen_p2x, screen_p2y)
open_terminal(screen_p1x, screen_p1y, screen_p2x-50, screen_p2y)

